package cn.bdqn.tangcco.user.controller;

import cn.bdqn.tangcco.entity.Tbuser;
import cn.bdqn.tangcco.user.service.UserServices;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2016/6/2.
 */
@Controller
public class LoginController {

    @Inject
    private UserServices userServices;

    @RequestMapping(value = {"/loginController"},method = RequestMethod.POST)
    public String login(Tbuser users, HttpSession session, Model model){
        String forward = "";

        Tbuser login = this.userServices.login(users);
        if (login != null) {
            session.setAttribute("users",login);
            forward = "main/main";

        } else {
            model.addAttribute("msg", "对不起，用户名或者密码错误!");
            forward = InternalResourceViewResolver.FORWARD_URL_PREFIX+"/index.jsp";
        }

        return forward;
    }




}
